//
// Description: 2028. 找出缺失的观测数据
// Created by Loading on 2021/10/5.
//

#include <bits/stdc++.h>

using namespace std;

vector<int> missingRolls(vector<int> &rolls, int mean, int n) {
    vector<int> res;

    int m = rolls.size();
    // 已经存在的点数和
    int sum = accumulate(rolls.begin(), rolls.end(), 0);
    // 需要的点数和
    int need_sum = mean * (m + n) - sum;
    // 需要的点数和非正，或需要的点数和过大，直接返回空
    if (need_sum <= 0 || need_sum > 6 * n) {
        return res;
    }

    // 需要的均值
    int avg = need_sum / n;
    // 均值为 0，直接返回
    if (avg == 0) {
        return res;
    }
    // 有几个点数需要比均值大 1
    int last = need_sum - avg * n;
    for (int i = 0; i < last; ++i) {
        res.emplace_back(avg + 1);
    }
    // 剩余点数为均值
    for (int i = 0; i < n - last; ++i) {
        res.emplace_back(avg);
    }

    return res;
}

int main() {
    vector<int> rolls = {4, 5, 6, 2, 3, 6, 5, 4, 6, 4, 5, 1, 6, 3, 1, 4, 5, 5, 3, 2, 3, 5, 3, 2, 1, 5, 4, 3, 5, 1, 5};
    int mean = 4;
    int n = 40;
    vector<int> res = missingRolls(rolls, mean, n);
    for (auto &x : res) {
        cout << x << ' ';
    }
    cout << endl;

    return 0;
}